# 接听原始行情，并发送给各个策略
from threading import Thread
from queue import Queue


class RawMDProcessor(Thread):
    raw_md_queue = Queue()
    stg_manager = None
    public_context = None

    def __init__(self):
        super().__init__()
        self.raw_md_queue = Queue()
        self.stg_manager = None
        self.public_context = None

    def set_raw_md_queue(self, raw_md_queue):
        self.raw_md_queue = raw_md_queue

    # def register_stg(self, stg_context):
    #     self.stg_manager.all_strategy_context = stg_context

    def run(self):
        print('listener started')
        while True:
            data = self.raw_md_queue.get()
            if data == 'SYSTEM_EXIT':
                break
            self.public_context.process_md(data)
            for key in self.stg_manager.all_strategy_context:
                self.stg_manager.all_strategy_context[key].put_md(data)
        return 0

    def finish(self):
        self.raw_md_queue.put('SYSTEM_EXIT')


